package com.guigu.jwy.controller;


import com.github.pagehelper.PageInfo;
import com.guigu.jwy.pojo.Page;
import com.guigu.jwy.service.ServiecDj;
import com.guigu.pojo.MManufacture;
import com.guigu.pojo.MProcedure;
import com.guigu.pojo.MProcedureModuling;
import com.guigu.pojo.SCell;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.util.Calendar;
import java.util.List;

@RestController
@RequestMapping("scdj")
public class ScdjController {
    @Qualifier("serviecDj")
    @Autowired
    ServiecDj serviec;
    @PostMapping("querydatil")
    public Page querydatil(MProcedureModuling mProcedureModuling){
        PageInfo pageInfo=serviec.querymps(mProcedureModuling );
        Page page=new Page();
        page.setRows(pageInfo.getList());
        page.setTotal(Integer.parseInt(pageInfo.getTotal()+""));
        return page;
    }
    @PostMapping("update")
    public ModelAndView update(MProcedureModuling mProcedureModuling, MProcedure mProcedure){
        String []id=mProcedureModuling.getProductId().toString().split(",");
        String []num=mProcedureModuling.getAmount().toString().split(",");
        serviec.updatemm(mProcedureModuling);
        mProcedure.setParentId(mProcedureModuling.getParentId());
        serviec.updatemp(mProcedure);
        for (int i=0;i<=id.length-1;){
            MProcedureModuling moduling=new MProcedureModuling();
            moduling.setAmount(Integer.parseInt(num[i]));
            moduling.setProductId(id[i]);
            serviec.updatemming(moduling);
            i++;
        }

        return null;
    }
    @PostMapping("queryr")
    public Page queryr(){
        PageInfo pageInfo=serviec.querysta();
        Page page=new Page();
        page.setRows(pageInfo.getList());
        page.setTotal(Integer.parseInt(pageInfo.getTotal()+""));
        return page;
    }
    @PostMapping("check")
    public ModelAndView check(MManufacture mManufacture){
        //需要跳页面
        serviec.check(mManufacture);
        return null;
    }
    @PostMapping("updatenum")
    public ModelAndView updatenum(MProcedure mProcedure){
        serviec.updatemnum(mProcedure);
        serviec.updatenum(mProcedure);
      /*  serviec.addrknum(mProcedure);*/
        String a=serviec.quersckool();
        SCell sCell=new SCell();
        Calendar cal=Calendar.getInstance();
        int y=cal.get(Calendar.YEAR);
        int m=cal.get(Calendar.MONTH)+1;
        int d=cal.get(Calendar.DATE);
        sCell.setStoreId("400"+y+m+d+a);
        int b=Integer.parseInt("100"+a)+1;
        String q=""+b;
        q=q.substring(3);
        mProcedure.setParentId(Integer.parseInt(q));
        serviec.addrknum(mProcedure);

        return null;
    }
    @PostMapping("view")
    public Page view(){
        PageInfo pageInfo=serviec.view();
        Page page=new Page();
        page.setRows(pageInfo.getList());
        page.setTotal(Integer.parseInt(pageInfo.getTotal()+""));
        return page;
    }
}
